<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>安检记录详情</title>
</head>
<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">

<link rel="stylesheet" href="../../src/dist/css/page.css">

<body>
<div class="weui-cells SecurityRecord-detail">
    <div class="weui-cells__tips">用户详情</div>
    <div class="weui-cells" id="DemoBaseInfo">
        <img src="../../src/dist/img/nodata.png" alt="" class="nodataImg">
    </div>
    <div class="weui-cells__tips">燃气表信息</div>
    <div class="weui-cells" id="DemoGasMeterInfo"></div>
    <div class="weui-cells__tips">隐患情况</div>
    <div class="weui-cells" id="DemoDangerInfo"></div>
    <div class="weui-cells__tips">图片</div>
    <div class="weui-cells" id="DemoTaksFile"></div>
</div>

<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<!-- Dist -->
<script src="../../src/dist/js/index.js"></script>
<script src="../../src/dist/js/utils.js"></script>
<script src="../../src/dist/js/request.js"></script>
<script>
    var detailData = [],
		id = '';
    $(function(){
        var paras = location.search;            //search获得地址中的参数，内容为'?itemId=12'
        var result = paras.match(/[^\?&]*=[^&]*/g);     //match是字符串中符合的字段一个一个取出来，result中的值为['login=xx','table=admin']
        paras = {};                    //让paras变成没有内容的json对象
        for (i in result) {
            var temp = result[i].split('=');    //split()将一个字符串分解成一个数组,两次遍历result中的值分别为['itemId','xx']
            paras[temp[0]] = temp[1];
        }
		id = paras.id;     //根据参数名"itemId"，获取参数值

        //getSecurityRecordDetail()   //真实接口数据
		getSecurityRecordDetailPHP() // 本地测试数据
    })

    function getSecurityRecordDetailPHP() {
        $.ajax({
            type: "POST",
            url: "../../src/php/requestOnline.php",
            data: {
                act: 'CSRQ_getSecurityRecordDetail'
            },
            success: function (data) {
                data = eval('(' + data + ')')
				detailData = data
                createListDemo()
            },
            error: function (data) {

            }
        });
	}
    function getSecurityRecordDetail() {
			// customid = '1020000015'
        $.ajax({
            type: "POST",
            url: CJINGdataLink+"/Controllers/CustomerServiceCenter/PartyCheckHandler.ashx",
            data: {
                cmd: " viewcheckform  ", JsonData: JSON.stringify({TaskID  :id })
            },
            success: function (data) {
                data = eval('(' + data + ')')
                if(data.list.length ===0 ){
                    $.toast('暂无数据!', 'text');
                    return
                }
                detailData = data
                createListDemo()
            },
            error: function (data) {
                $.toast('获取数据失败!', 'forbidden');
            }
        });
	}
	function createListDemo(){
			let d = detailData.BaseInfo
			let h = ''

        //处理用户信息
            h += '<div class="detail">' +
                    '<i class="iconfont iconshijian"></i>' +
                    '<span class="s1">安检时间</span>' +
                    '<span class="s2">'+d.CheckDate+'</span>' +
                '</div>' +
                '<div class="detail">' +
                    '<i class="iconfont iconleixing"></i>' +
                    '<span class="s1">用户类型</span>' +
                    '<span class="s2">'+d.PersonTypeName+'</span>' +
                '</div>'+
                '<div class="detail">' +
                    '<i class="iconfont icondizhi"></i>' +
                    '<span class="s1">地址</span>' +
                    '<span class="s2">'+d.Address+'</span>' +
                '</div>'+
                '<div class="detail">' +
                    '<i class="iconfont iconyonghuming"></i>' +
                    '<span class="s1">用户姓名</span>' +
                    '<span class="s2">'+d.Name+'</span>' +
                '</div>'+
                '<div class="detail">' +
                    '<i class="iconfont icondianhua"></i>' +
                    '<span class="s1">联系电话</span>' +
                    '<span class="s2">'+d.Phone1+'</span>' +
                '</div>'+
                '<div class="detail">' +
                    '<i class="iconfont iconzhuangtai"></i>' +
                    '<span class="s1">安检状态</span>' +
                    '<span class="s2">'+d.PartyStatusName+'</span>' +
                '</div>'+
                '<div class="detail">' +
                    '<i class="iconfont iconzhanghao"></i>' +
                    '<span class="s1">安检人员</span>' +
                    '<span class="s2">'+d.CheckMan+'</span>' +
                '</div>'


			$("#DemoBaseInfo").html(h)

        // 处理燃气表信息
        let h2 = '<div class="detail">' +
                '<i class="iconfont iconbianhao"></i>' +
                '<span class="s1">表具编号</span>' +
                '<span class="s2">'+d.GasMeterCode+'</span>' +
            '</div>' +
            '<div class="detail">' +
                '<i class="iconfont iconleixing"></i>' +
                '<span class="s1">表具类型</span>' +
                '<span class="s2">'+d.GasMeterTypeName+'</span>' +
            '</div>'+
            '<div class="detail">' +
                '<i class="iconfont iconbiaojuleixing"></i>' +
                '<span class="s1">表具型号</span>' +
                '<span class="s2">'+d.BrandModelOfGasMeter+'</span>' +
            '</div>'+
            '<div class="detail">' +
                '<i class="iconfont iconfangxiang"></i>' +
                '<span class="s1">表向</span>' +
                '<span class="s2">'+d.SurfaceDirection+'</span>' +
            '</div>'+
            '<div class="detail">' +
                '<i class="iconfont icontec"></i>' +
                '<span class="s1">表积累</span>' +
                '<span class="s2">'+d.meterCumulative+'</span>' +
            '</div>'+
            '<div class="detail">' +
                '<i class="iconfont iconshengyu"></i>' +
                '<span class="s1">表余量</span>' +
                '<span class="s2">'+d.meterSurplus+'</span>' +
            '</div>'
		$("#DemoGasMeterInfo").html(h2)
        //隐患情况信息
        let d3 = detailData.FormInfo

        let h3 = '<div class="dangerinfo">'
        for (let [index, item] of d3.Children.entries()) {
            //console.log(item);
            let h31 = '<div class="dangerName">'+item.Name+'：</div>' +
                '<div class="dangesInfo">'
            let d31 = item.Children
            if(item.Name == '温馨提示'){
                h31+='<div class="wenxintishi">'+item.HCheckTypeWorkList[0]['Name']+'</div>'
                h31 += '</div>'

                h3 += h31
            }
            if(d31.length ===0 || item.Name == '燃气检测')continue
            for(let[ii,item2] of d31.entries()){
                //console.log(item2.Name,item2.Children[1].HCheckTypeWorkList);
                /**
                 * item2.Children
                 * 0:正常
                 * 1：不正常
                 */
                let d311 = item2.Children[1].HCheckTypeWorkList
                let isdanger = ''
                for(let[ii3,item3] of d311.entries()){
                    if(Number(item3.DataValue) == 1)isdanger = 'isdanger'
                }

                h31 += '<span class="'+isdanger+'" onclick="dangeInfoClick(this)" weizhi="FormInfo-'+index+'-'+ii+'">'+item2.Name+'</span>'
            }
            h31 += '</div>'

            h3 += h31
        }
        h3+='</div>'
        $("#DemoDangerInfo").html(h3)

        // 图片
        let d4 = detailData.TaksFile.initialPreview
        let h4 = '<div class="imagesDemo">'
        for(let [i,item] of d4.entries()){
            h4+= '<img src="'+item+'">'
        }
        h4+='</div>'
        $("#DemoTaksFile").html(h4)
    }

    // 点击隐患项
    function dangeInfoClick(obj) {
        let w = $(obj).attr("weizhi")
        let a = w.split("-")
        let isdanger = $(obj).hasClass("isdanger")
        if(!isdanger){
            return
        }

        let c = detailData[a[0]]['Children'][a[1]]['Children'][a[2]]['Children'][1]['HCheckTypeWorkList']

        let h = ''
        for(let [i,item] of c.entries()){
            console.log(item)
            if(Number(item.DataValue) == 1){
                h += '<span style="display: inline-block;margin: 2vw;padding: 2vw;font-size: 0.7rem;background: #FFE5B8;color:#f3a626;border-radius: 3px;">'+item.Name+'</span>'
            }
        }
        $.modal({
            title: "隐患情况",
            text: h,
            buttons: [
                { text: "关闭", className: "default", onClick: function(){ console.log(3)} },
            ]
        });
    }

</script>
</body>
</html>
